<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 平台消息 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.name" placeholder="用户名" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column type="index" label="编号" width="55" align="center"></el-table-column>
                <el-table-column prop="userid" label="用户名"></el-table-column>
                <el-table-column prop="xiaoxi" label="消息"></el-table-column>
                <el-table-column prop="type" label="类型"></el-table-column>
                <el-table-column prop="time" label="时间"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="5"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { fetch_data_with_credit, update_status, fetch_major,shuliang } from '../../api/index';
import Axios from 'axios';
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                id: '',
                name: '',
                a: 0,
                b: 5
            },
            options_class: [
                {
                    value: '1',
                    label: '1'
                },
                {
                    value: '2',
                    label: '2'
                },
                {
                    value: '3',
                    label: '3'
                }
            ],
            options_major: [
                {
                    value: '计算机科学与技术',
                    label: '计算机科学与技术'
                },
                {
                    value: '数字媒体',
                    label: '数字媒体'
                }
            ],
            major: {},
            value_class: '',
            value_major: '',
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            graduateVisible: false,
            recoverVisible: false,
            suspenVisible: false,
            exitVisible: false,
            pageTotal: 0,
            form: {},
            form_add: {},
            origin: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getData();
        
    },
    methods: {
        getMajor() {
            fetch_major().then(res => {
                // console.log(res.data);
                this.major = res.data;
            });
        },
        getData() {
            fetch_data_with_credit(this.query).then(res => {
                console.log(res);
                this.tableData = res.data.data;
                // this.pageTotal = res.data.pagetotal || 5;
            });
            shuliang(this.query).then(res => {
                console.log(res);
                this.pageTotal = res.data.data || 5;
            })
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>

